
package line.basic.axis;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 * 變換 Y 軸刻度單位<br>
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class ChangeValueAxisTickUnit
{
	private String rowKey = "price";

	private String columnKey1 = "06/01";

	private String columnKey2 = "06/02";

	private String columnKey3 = "06/03";

	private String columnKey4 = "06/04";

	private String columnKey5 = "06/05";

	private String title = "個別房價指數";

	private String categoryAxisLabel = "估價時間";

	private String valueAxisLabel = "總價(萬元)";

	private PlotOrientation orientation = PlotOrientation.VERTICAL;

	public ChangeValueAxisTickUnit()
	{
		JFreeChart chart = createLineChart();

		// get plot
		CategoryPlot plot = chart.getCategoryPlot();

		NumberAxis numberAxis = ( NumberAxis )plot.getRangeAxis();

		// 設定刻度單位為 200
		NumberTickUnit unit = new NumberTickUnit( 200 );

		numberAxis.setTickUnit( unit );

		display( chart );
	}

	public static void main( String[] args )
	{
		new ChangeValueAxisTickUnit();
	}

	private JFreeChart createLineChart()
	{
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		dataset.addValue( 841, rowKey, columnKey1 );
		dataset.addValue( 850, rowKey, columnKey2 );
		dataset.addValue( 832, rowKey, columnKey3 );
		dataset.addValue( 800, rowKey, columnKey4 );
		dataset.addValue( 900, rowKey, columnKey5 );

		return ChartFactory.createLineChart( title, categoryAxisLabel, valueAxisLabel, dataset, orientation, false, true, false );
	}

	private void display( JFreeChart chart )
	{
		ChartFrame frame = new ChartFrame( "Test", chart );
		frame.pack();
		frame.setVisible( true );
	}
}
